package com.hq.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hq.pojo.Comment;
import com.hq.service.CommentService;
import com.hq.service.ConverService;
import com.hq.service.impl.CommentImpl;
import com.hq.service.impl.ConverImpl;
import com.hq.utils.JSONObjectUtil;

/**
 * Servlet implementation class InsertCommentServlet
 */
@WebServlet("/InsertCommentServlet")
public class InsertCommentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter print = response.getWriter();
		//话题ID
		String converId = request.getParameter("cid");
		String accountId = request.getParameter("aid");
		String content = request.getParameter("content");
		CommentService service = new CommentImpl();
		int i = service.insertComment(getComment(Integer.valueOf(converId), Integer.valueOf(accountId), content));
		print.print(JSONObjectUtil.createInsertCommentResult(i));
		print.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
	
	
	private Comment getComment(int converId,int accountId,String content){
		Comment comment = new Comment();
		comment.setConver_id(converId);
		comment.setAccount_id(accountId);
		comment.setComment_content(content);
		return comment;
	}

}
